jsq.sellector={
    ELEMENT_NODE:1,
    ATTRIBUTE_NODE:2,
    TEXT_NODE:3,
    CDATA_SECTION:4,
    ENTITY_REFERENCE:5,
    ENTITY_NODE:6,
    COMMENT_NODE:8
	_regexp_search:function(obj,regexp) {
		var id,node,matches;
		var ret=[];
		var arr=(obj||document.body).getElementsByTagName('*');
		
		for(var i=0;i<arr.length;i++) {
			if (typeof arr[i].id=='undefined' || !arr[i].id) continue;
			matches=regexp.exec(arr[i].id);
			if (matches&&matches.length>0) {
				ret.push(arr[i]);
			}
		}
		arr=null;
		return ret;
	},
	_$$:function(id) {
	  var elements = [];
		var tmp=id.split('~');
		var findi=tmp[0].indexOf('##');
		if (findi==-1) return document.getElementById(tmp[0]);
		var stopAtError=tmp.length==1?true:false;
		var end=(tmp.length>1)?tmp[1]:-1;
		var pre=tmp[0].substring(0,findi);
		var post=tmp[0].substr(findi+2);

		for(var i=1;true;i++) {
			var num=(i<10?'0':'')+i;
			var name=pre+num+post;
			var el=document.getElementById(name);
			if (el) {
				elements.push(el);
				el=null;
			}
			else {
				if (stopAtError==true) break;
			}
			if (end>0 && i==end) break;
		}
		return elements;
	},
	getElementsByClassName:function(obj,className) {
	  var children = obj.getElementsByTagName('*');
	  var regexp=new RegExp("(^|\\s)" + className + "(\\s|$)");
	  var elements=[];
	  for(var i=0;i<children.length;i++) {
	  	var child=children[i];
	  	if (child.className.match(regexp)) elements.push(child);
	  }
	  children=null;
	  regexp=null;
		return elements;
	},
	getElementFromForm:function(location) {
		var tmp=location.split('.');
		return (tmp.length>1)?document.forms[tmp[0]][tmp[1]]:document.forms[location];
	},
	getElementsFromParent:function(element) {
		var win=window;
		var tmp=$(element);
		var ret=[];
		if (tmp) {
			if (typeof tmp.length=='number') ret=$A(tmp);
			else ret.push(tmp);
		}
		for(;win.parent;win=win.parent) {
			try {
				if (!win.parent.document || !win.parent.document.body || typeof win.parent.swaf=='undefined') break;
				if (win.parent.document.body.tagName!='BODY') break;
				if (window.top==win) break;
			} catch(e) { break;}
			tmp=win.parent.$(element);
			if (typeof tmp.length=='number') ret=ret.concat($A(tmp));
			else ret.push(tmp);
		}
		return ret;
	},
	_selector_sub:{
		35:function(element,root) { // # - tag
			element=(root||document).getElementsByTagName(element);
			if (element.length==1) element=element[0];
			else if (element.length==0) element=undefined;
			return element;
		},
		64 : function(element,root) {// @ - name
			element=document.getElementsByName(element);
			if (element.length==1) element=element[0];
			else if (element.length==0) element=undefined;
			return element;
		},
		46 : function(element,root) { // . - class
			element=jsq.sellector.getElementsByClassName((root||document),element);
			if (element.length==1) element=element[0];
			else if (element.length==0) element=undefined;
			return element;
		},
		37 : function(element,root) { // % - form
			return jsq.sellector.getElementFromForm(element);
		},
		42 : function(element,root) { // * - node index
			var node=(root||document).firstChild;
			if (node) node=node.nextSibling;
			else return null;
			for(var i=0;node&&i<element;node=node.nextSibling) {
				if (node.nodeType==jsq.sellector.ELEMENT_NODE) i++;
			}
			return node;
		},
		126 : function(element,root) { // ~ - ##
			return jsq.sellector._$$(element);
		},
		43 : function(element,root) { // + - find child frame
			return jsq.gs.$(element);
		},
		94 : function(element,root) { // ^ - find parent frame
			return jsq.sellector.getElementsFromParent(element);
		}
	},
	$ : function(element,root) {
	  if (typeof element == 'string') {
	  	var selectorfn=jsq.sellector._selector_sub[element.charCodeAt(0)];
	  	if (selectorfn) element=selectorfn(element.substr(1),root);
	  	else element=document.getElementById(element);
	  }
	  else if (element instanceof RegExp) return jsq.sellector._regexp_search(root,element);	// regexp
	  return element; // element
	}
};

var swaf={
	NAMESPACE:'swaf',
	version:'2.0',
	build:'%%BUILD%%',
	ScriptRegExp1:/<script[^>]*>([\u0001-\uFFFF]*?)<\/script>/gmi,
	ScriptRegExp2:/<script[^>]*>([\u0001-\uFFFF]*?)<\/script>/mi,
	define:{
	},
	ext:{},
	dummy:{},
	_set_attribute:function(el,name,value) {
		if (typeof el!='string' && typeof el.length=='number') {
			for (var i=0;i<el.length;i++) {
				if (el[i]) el[i].setAttribute(name,value);
			}
		} else if (el) el.setAttribute(name,value);
	},
	onLoadDocument:function() {
		if (typeof window.main == "function") window.main.call(window);
	},
	onUnloadDocument:function() {
		if (typeof window.exit== "function") window.exit.call(window);
	}
};

swaf.$=function(element,root) {
  if (typeof element !='string' && typeof element.length=='number' && element[0]) {
  	var ret=[];
    for (var i = 0, elements = [], length = element.length; i < length; i++) { ret.push[swaf._$(element[i],root)];}
    return ret;
  }
  return swaf._$(element,root);
};

if (typeof $=='undefined') var $=swaf.$;

swaf.$A=function(obj) {
	var ret=[];
	if (obj.toArray) return obj.toArray();
	if (typeof obj.length=='number') {
		for(var i=0;i<obj.length;i++) { ret[i]=obj[i]; }
	}
	return ret;
};
if (typeof $A=='undefined') var $A=swaf.$A;

swaf.extend=function(destination, source, override) {
  for (var property in source) { 
    if (override==false && typeof destination[property] !='undefined') continue;
    destination[property] = source[property]; 
  }
  return destination;
};
if (typeof $extend=='undefined') var $extend=swaf.extend;

swaf.include=function(url) {
	var head=document.getElementsByTagName("head");
	if (head) {
		var linkel=document.createElement('script');
		linkel.setAttribute('src', url);
		linkel.setAttribute('type', 'text/javascript');
		head[0].appendChild(linkel);
	}
	head=null;
};
if (typeof $include=='undefined') var $include=swaf.include;

swaf.ext.Array={
	find : function(item) {
		for(var i=0;i<this.length;i++) {if (this[i]==item) return i;}
		return -1;
	},
	copy:function() {
		var ret=new Array(this.length);
		for(i=0;i<this.length;i++) {
			var obj=this[i];
			if (obj instanceof Array) ret[i]=this[i].copy();
			else ret[i]=obj;
		}
		return ret;
	},
	// arg : ...
	each : function(fn,optional_arg) {
		var arg=[null,0];
		if (optional_arg) {
			var tmparg=swaf.$A(arguments);
			tmparg.shift();
			arg=arg.join(tmparg);
		}
		for(var i=0;i<this.length;i++) {
			arg[0]=this[i];
			arg[1]=i;
			fn.apply(fn,arg);
		}
		return this;
	},
	remove:function(value) {
		var ret=[];
		for(var i=0;i<this.length;i++) { if (this[i]==value) {ret.push(this[i]);delete this[i]; }}
		return ret;
	},
	removeCompact:function(value) {
		var ret=[];
		for(var i=0;i<this.length;i++) { if (this[i]==value) ret.push(this.splice(i,1)); }
		return ret;
	},
	last:function() {
		return this[this.length-1];
	},
	tryFn:function() {
		for(var i=0;i<this.length;i++) {
			if (typeof this[i]!='function') continue;
			try { return this[i].apply(window,arguments); }
			catch(e) { continue; }
		}
		return null;
	}
};

swaf.ext.String={
	trim : function() {return this.replace(/^\s+|\s+$/g,''); 	},
	ltrim : function() {return this.replace(/^\s*/g,''); 	},
	rtrim : function() {return this.replace(/\s*$/g, ''); 	},
	stripTags : function() { 	 return this.replace(/<\/?[^>]+>/gi, ''); 	},
	stripScripts : function() { 	  return this.replace(swaf.ScriptRegExp1, '');	},
	extractScripts : function() {
		var ret=[];
		var tmp=this.match(swaf.ScriptRegExp1) || [];
		for(var i=0;i<tmp.length;i++) {
			ret.push((tmp[i].match(swaf.ScriptRegExp2) || ['', ''])[1]);
		}
		tmp=null;
		return ret;
	},
  evalScripts: function() {
  	var scripts=this.extractScripts();
  	for(var i=0;i<scripts.length;i++) eval(scrips[i]);
  },
	escapeHTML : function() {	  return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/\"/g,'&quot;');	},
	unescapeHTML : function() {		return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');	},
  toArray: function() {
    return this.split('');
  },

	toObject : function() {
		var names=this.split('.');
		var obj=window;
		for(i=0;i<names.length;i++) { obj=obj[names[i]]; }
		names=null;
		return obj;
	},
	_set_param:function(name,value) {
		var regexp=new RegExp('\\{\\$'+name+'\\}','gm');
		return this.replace(regexp, value);
	},
	_set_param_obj:function(object) {
		var str=this;
		for(var property in object) {
			str=str._set_param(property,object[property]);
		}
		return str;
	},
	set:function(name,value) {
		if (typeof name=='object') return this._set_param_obj(name);
		return this._set_param(name,value);
	},
	byteTruncate:function(maxlen,encoding) {
		encoding=encoding?encoding.toLocaleLowerCase():'utf-8';
		var mbl=(encoding=='utf-8')?3:2;
		var len=0;
		var strlen=this.length;
		var ret='';
	  for(var i=0;i<strlen;i++) {
	      var c=this.charAt(i);
	      if (escape(c).length>4) len+=mbl;
	      else len++;
	      if (len<=maxlen) ret+=c;
	      else break;
	  }
	  return ret;
	},
	byteLength:function(encoding) {
		encoding=encoding?encoding.toLocaleLowerCase():'utf-8';
		var mbl=(encoding=='utf-8')?3:2;
		var len=0;
		var strlen=this.length;
	  for(var i=0;i<strlen;i++) {
	      var c=this.charAt(i);
	      if (escape(c).length>4) len+=mbl;
	      else len++;
	  }
	  return len;
	}
};

swaf.ext.Number={
	leadingZero:function(len) {
		var tmp='000000000000'+this;
		return tmp.substr(tmp.length-len,len);
	}
};

// function extension
swaf.ext.Function={
	bind : function() {
	  var __method = this;
	  var args = swaf.$A(arguments);
	  var owner = args.shift();
	  return function() {
	    return __method.apply(owner, args.concat(swaf.$A(arguments)));
	  }
	},
	bindAsEventListener : function() {
	  var __method = this;
	  var args = swaf.$A(arguments);
	  var owner = args.shift();
	  var ret=function(event) {
	  	var evt=event || window.event;
	  	var src=arguments.callee.eventSrc;
	  	if (!evt.target) evt.target=src;
	    return __method.apply(owner, [new swaf.eventObject(evt),src,evt.type].concat(args));
	  };
	  ret.__swaf__bindedAsListener=true;
	  return ret;
	},
	getProxy:function(owner,before,after,exception) {
	    var fn=this;
		if (before&&after&&exception) {
			return function() {
				try {
					before.apply(owner,arguments);
					fn.apply(owner,arguments);
					after.apply(owner,arguments);
				}
				catch(e) {
					exception.call(owner,error,fn,arguments);
				}
			};
		} else if (!before&&after&&exception) {
			return function() {
				try {
					fn.apply(owner,arguments);
					after.apply(owner,arguments);
				}
				catch(e) {
					exception.call(owner,error,fn,arguments);
				}
			};
		} else if (before&&!after&&exception) {
			return function() {
				try {
					before.apply(owner,arguments);
					fn.apply(owner,arguments);
				}
				catch(e) {
					exception.call(owner,error,fn,arguments);
				}
			};
		} else if (before&&after&&!exception) {
			return function() {
				before.apply(owner,arguments);
				fn.apply(owner,arguments);
				after.apply(owner,arguments);
			};
		} else if (!before&&!after&&exception) {
			return function() {
				try {
					fn.apply(owner,arguments);
				}
				catch(e) {
					exception.call(owner,error,fn,arguments);
				}
			};
		} else if (!before&&after&&!exception) {
			return function() {
				fn.apply(owner,arguments);
				after.apply(owner,arguments);
			};
		} else if (before&&!after&&!exception) {
			return function() {
				before.apply(owner,arguments);
				fn.apply(owner,arguments);
			};
		} else {
			return function() {
				fn.apply(owner,arguments);
			};
		}
	}
};

// etc
swaf.ext.Object={
    toQueryString : function(obj) {
      var parts = [];
    	for(var key in obj) {
    		var value=obj[key];
    		parts.push(encodeURIComponent(key)+'='+(value?encodeURIComponent(value):''));
    	}
      return parts.join('&');
    }
};
if (typeof Object.toQueryString == 'undefined') Object.toQueryString=swaf.ext.Object.toQueryString;

swaf.extend(Array.prototype,swaf.ext.Array,false);
swaf.extend(String.prototype, swaf.ext.String,false);
swaf.extend(Number.prototype, swaf.ext.Number,false);
swaf.extend(Function.prototype, swaf.ext.Function,false);

swaf.namespace=function(name,define) {
	var names=name.split('.');
	var obj=window;
	var last=names.length-1;
	var ns='';
	for(i=0;i<last;i++) {
	    if (ns.length>0) ns+='.';
	    ns+=names[i];
		if (typeof obj[names[i]]=='undefined') obj[names[i]]={NAMESPACE:ns};
		obj=obj[names[i]];
	}
	if (!obj[names[last]]) {
		if (define) {
			obj[names[last]]=define;
			(obj[names[last]]).NAMESPACE=name;
		}
		else obj[names[last]]={NAMESPACE:name};
	}
	obj=null;
};

if (typeof $namespace == 'undefined') var $namespace=swaf.namespace;

swaf.attr=function(el,name,value) {
	if (typeof el=='undefined') return null;
	if (value) { swaf._set_attribute(el,name,value); return null;}
	if (typeof el!='string' && typeof el.length=='number') {
		var ret=[];
		for (var i=0;i<el.length;i++) {
			ret.push((el[i])?el[i].getAttribute(name):null);
		}
		return ret;
	}
	return el.getAttribute(name);
};

if (typeof $attr == 'undefined') var $attr=swaf.attr;

swaf.$a=function(el,name,value) {
	return swaf.attr(el,'swaf:'+name,value);
};

if (typeof $a == 'undefined') var $a=swaf.$a;